package com.amat0urheu.controller.adminController;


import com.alibaba.fastjson.JSONObject;
import com.amat0urheu.pojo.CloudPojo.IpPort;
import com.amat0urheu.pojo.CloudPojo.OpenStack;
import com.amat0urheu.pojo.ReturnRes;
import com.amat0urheu.service.cloudService.CloudService;
import com.amat0urheu.service.cloudService.IpPortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class IpPortController {
    @Autowired
    CloudService cloudService;
    @Autowired
    IpPortService ipPortService;
    //    @PreAuthorize("hasAuthority('ROLE_user')")
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @GetMapping("/cloud/getAllIpPort/{pageSize}/{pageNum}")
    ReturnRes getIpPort(@PathVariable int pageSize,
                              @PathVariable int pageNum) {

        return   ipPortService.getIpports(pageSize, pageNum);
    }
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @PostMapping("/cloud/saveIpPort")
    public ReturnRes RequestParam(@RequestParam(name = "data") String ipPortJson) {
        IpPort ipPort = JSONObject.parseObject(ipPortJson, IpPort.class);

        return  ipPortService.saveIpport(ipPort) /* cloudService.saveOpenstack(openStack)*/;
    }
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @PostMapping("/cloud/removeIpport")
    public ReturnRes removeIpport(@RequestParam(name = "id") Integer id) {



        return ipPortService.removeIpport(id);
    }
}